package com.dotflat.check.service.impl;

import com.dotflat.check.domain.DeviceRecord;
import com.dotflat.check.repository.DeviceRecordRepository;
import com.dotflat.check.service.DeviceRecordService;
import com.dotflat.rest.service.impl.AreableObjectBaseServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;


@Service
public class DeviceRecordServiceImpl extends AreableObjectBaseServiceImpl<DeviceRecord, DeviceRecordRepository> implements DeviceRecordService {

    @Autowired
    @Override
    public void setBaseRepository(DeviceRecordRepository repository) {
        super.setBaseRepository(repository);
    }

    @Autowired
    private DeviceRecordRepository deviceRecordRepository;

    @Override
    public List<DeviceRecord> newestList(String areaId) {
        List<Integer>  list = deviceRecordRepository.getTypeList(areaId);
        List<DeviceRecord> list1 = new ArrayList<>();
        for (int i = 0; i <list.size() ; i++) {
            DeviceRecord deviceRecord =   deviceRecordRepository.getNewest(areaId,list.get(i));
            if (Objects.nonNull(deviceRecord)){
                list1.add(deviceRecord);
            }else {
                deviceRecord = new DeviceRecord();
                list1.add(deviceRecord);
            }
        }
        return list1;
    }
}